la $t0, isr
mtc0 $t0, $15          # set ebase = isr

main:	
	
	li $t0 , 0x11
	sw $t0 , 0xffff0000 # leds = 0x13
	
aaaa:	j aaaa
	
	############## locate controllers ############
	lui $a1, 0xffff
	lw $a0 , drp_leds
	
	jal locate_controller
	
	li $t0, -1
	beq $v0 , $t0 , led_fail
	
	li $t0 , 0x13
	sw $t0 , 0xffff0000 # leds = 0x13
		
win:	j win

###############################
	
	ori $t1 , $0 , 0x3
	lui $t0, 0xffff	 	# set offset for MMIO
	
	sw $t1, 0xf0($t0)	# timer.repeats[0] = true.
				#(timer addr = 0xc0 + repeats_offset = 12*4 = 0x30 ) = 0xf0
	li $s0 , 0
	
	# enable timer interrupts for 250ms...
	li $t1 , 0x1
	sw $t1 , 0xf4($t0)  # timer.interruptEnables[0] = true. ieHandler+(timer) = 0xc0 + 0x38 = 0xf8
	
	# initiate beat period
	li $t1 , 6250000	# 250ms
	sw $t1, 0xc0($t0)
	# initiate kick freq timer!
	li $t1 , 312500	# 80Hz. if we flip each event.
	sw $t1, 0xc4($t0)

	
###############################
led_fail:
	li $t0 , 0xAC
	sw $t0 , 0xffff0000 # leds = 0xAC
dead:	j dead

###############################
				
			
isr:
	

isr_i2s_sample:
	
	
	
	
	eret
isr_kick_setup:
	# initiate kick duration!
	li $t1 , 1000000
	sw $t1, 0xc8($t0)
	li $t2 , 0x3FFFFFFF	#init amplitude
	sw $t2 , bass_peak_amp
	
	eret
	
isr_kick_fundamental_flip:
	
	
	eret

	
######################################################################################
### locate_controller &controller (int drp_id , &mmio_controller)
### uses:	$t0
###		$t1
###
### entry:	$a0 = drp_id
###		$a1 = -> first controller you want to check. ( supports duplicate controllers ) if you want to check all start at mmio = 0xffff0000
###
### exit:  	$v0 = -> controller

locate_controller:
	move $t0 , $a1					# $t0 = -> controller[0]
	
loop_locate_controller:
	lw $t1 , 0xfc($t0)				# $t1 = controller[i].DRP_ID
	
	beq $t1 , $a0 , locate_controller_success	# if ( drp_id == controller[i].DRP_ID ) success!
	
	addiu $t0, $t0 , 0x40	# $t0 += 0x40		#$t0 -> controller[i++]
	beqz $t0 , end_locate_controller_fail 		# if it was not found fail.
	nop
	
	j loop_locate_controller			# else try again
	
locate_controller_success:
	move $v0 , $t0		# $v0 = -> controller	# success.
	jr $ra
	
end_locate_controller_fail:
	li $v0 , -1		# $v0 = -1.		# fail. would have used zero, but I think that's a valid address.
	jr $ra
###
###
###
######################################################################################


	
.data
.word
drp_timer:	0XA004001A
drp_leds:	0XA001001A
drp_switches:	0xA001002A
# bass
bass_peak_amp:	0	#
bass_curr_amp:	0	#
bass_decay:	0	# multiplied by 
bass_period:	0	#
